package com.demo2do.fms.entity.business;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.format.annotation.DateTimeFormat;

import com.demo2do.fms.entity.business.shipment.TransType;
import com.fasterxml.jackson.annotation.JsonFormat;

/**
 * 调度指令（用于委托方销单、勾选订单送SAP、报销）
 * 
 * @author Wy
 *
 */
@Entity
@Table(name = "TBL_ALL_SHIPMENT")
@DynamicUpdate
public class Shipment {
    
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "generator")
    @SequenceGenerator(name = "generator", sequenceName = "HIBERNATE_SEQUENCE", allocationSize = 1)
    private Long id;
    
    /** 调度指令号  */
    private String loadNumber;
    
    /** 调度指令组号  */
    private String loadGroupNumber;
    
    /** 派车单号 */
    private Long dispatchOrderId;
    
    /** 小订单号  */
    private Long shipmentId;
    
    private Long orderId;
    
    private Long loadId;
    
    private Long originalPlaceId;
    
    private Long firstShipmentId;
    
    /** 结算方(承接方) */
    private Long balanceId;
    
    /** 客户 */
    private Long customerId;
    
    /** 承运商(承运方)  */
    private Long transCorpId;
    
    /** 制造商ID  */
    private Long vhModelId;
    
    /** 驳运车ID */
    private Long transMeansId;
    
    /** 商品车颜色Id */
    private Long vhColorId;
    
    /** 车型Id */
    private Long vhCartypeId;
    
    /**商品车类型*/
    private String carSummary;
    
    private String vinCode;
    
    /** 装车道号  */
    private String driveWay;
    
    /** 调度顺序 */
    private String shipSequence;
    
    /** 起始地 */
    private Long srcWhId;
    
    /** 目的地 */
    private Long destWhId;
    
    /**  目的地联系人 */
    private String destContactPerson;
    
    /**  目的地联系电话 */
    private String destContactPhone;
    
    /**  目的地联系地址 */
    private String destContactAddr;
    
    /** 调度方式
     * 
     * 		- 数据库两字节存储, 不足右补空格 
     */
    private String transType;
    
    /** */
    private Long quantity;
    
    /** 调度数量 */
    private Long loadQuantity;
    
    /** 
     * 状态
     *      - 1 生效
     *      - 2 已派车
     *      - 3 已回单确认(已完成)
     *      - 4 已绑定
     *      - 5 已到达 
     */
    private Long status;
    
    /** 调度日期  */
    private Date shipmentDate;
    
    /** 预计装运时间 */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(shape=JsonFormat.Shape.STRING , pattern ="yyyy-MM-dd")
    private Date loadingTime;
    
    /** 预计起运时间 */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(shape=JsonFormat.Shape.STRING , pattern ="yyyy-MM-dd")
    private Date leavingTime;
    
    /** 预计到达时间 */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(shape=JsonFormat.Shape.STRING , pattern ="yyyy-MM-dd")
    private Date arrivingTime;
    
    /** 回单确认日期 */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date accConfirmDate;
    
    /** 操作人 */
    private String operator;
    
    /** 最后修改时间 */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date lastModifiedDate;
    
    /** 是否回单确认 */
    @Column(name = "is_accomplish_confirm")
    private Boolean accomplishConfirm;
    
    /** 是否电子回单确认 */
    @Column(name = "IS_ELECTRONIC_CONFIRM")
    private Boolean electronicConfirm;
    
    @Column(name = "is_accident")
    private Boolean accident;
    
    /**  */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date accidentTime;
    
    @Column(name = "is_disabled")
    private Boolean disabled;
    
    /**
     * 
     * the default constructor
     */
    public Shipment() {
        
    }
    
    /**
     * 回单确认 - 用于报销
     * 
     * @param accConfirmDate
     * @param operator
     * @param lastModifiedDate
     * @return
     */
    public Shipment accomplishConfirm(Date accConfirmDate, String operator, Date lastModifiedDate){
        this.accomplishConfirm = true;
        this.accConfirmDate = accConfirmDate;
        this.operator = operator;
        this.lastModifiedDate = lastModifiedDate;
        return this;
    }
    
    /**
     * @return
     */
    public boolean disabled() {
        return this.disabled;
    }
    
    /**
     * @return the transType
     */
    @Transient
    public TransType getTransType() {
    	
    	if (StringUtils.isBlank(transType)) {
    		return null;
    	}
    	
        return TransType.ordinalOf(transType);
        
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the loadNumber
     */
    public String getLoadNumber() {
        return loadNumber;
    }

    /**
     * @return the loadGroupNumber
     */
    public String getLoadGroupNumber() {
        return loadGroupNumber;
    }

    /**
     * @return the dispatchOrderId
     */
    public Long getDispatchOrderId() {
        return dispatchOrderId;
    }

    /**
     * @return the shipmentId
     */
    public Long getShipmentId() {
        return shipmentId;
    }

    /**
     * @return the orderId
     */
    public Long getOrderId() {
        return orderId;
    }

    /**
     * @return the loadId
     */
    public Long getLoadId() {
        return loadId;
    }

    /**
     * @return the originalPlaceId
     */
    public Long getOriginalPlaceId() {
        return originalPlaceId;
    }

    /**
     * @return the firstShipmentId
     */
    public Long getFirstShipmentId() {
        return firstShipmentId;
    }

    /**
     * @return the balanceId
     */
    public Long getBalanceId() {
        return balanceId;
    }

    /**
     * @return the customerId
     */
    public Long getCustomerId() {
        return customerId;
    }

    /**
     * @return the transCorpId
     */
    public Long getTransCorpId() {
        return transCorpId;
    }

    /**
     * @return the vhModelId
     */
    public Long getVhModelId() {
        return vhModelId;
    }

    /**
     * @return the transMeansId
     */
    public Long getTransMeansId() {
        return transMeansId;
    }

    /**
     * @return the vhColorId
     */
    public Long getVhColorId() {
        return vhColorId;
    }

    /**
     * @return the vhCartypeId
     */
    public Long getVhCartypeId() {
        return vhCartypeId;
    }

    /**
     * @return the carSummary
     */
    public String getCarSummary() {
        return carSummary;
    }

    /**
     * @return the vinCode
     */
    public String getVinCode() {
        return vinCode;
    }

    /**
     * @return the driveWay
     */
    public String getDriveWay() {
        return driveWay;
    }

    /**
     * @return the shipSequence
     */
    public String getShipSequence() {
        return shipSequence;
    }

    /**
     * @return the srcWhId
     */
    public Long getSrcWhId() {
        return srcWhId;
    }

    /**
     * @return the destWhId
     */
    public Long getDestWhId() {
        return destWhId;
    }

    /**
     * @return the destContactPerson
     */
    public String getDestContactPerson() {
        return destContactPerson;
    }

    /**
     * @return the destContactPhone
     */
    public String getDestContactPhone() {
        return destContactPhone;
    }

    /**
     * @return the destContactAddr
     */
    public String getDestContactAddr() {
        return destContactAddr;
    }

    /**
     * @return the quantity
     */
    public Long getQuantity() {
        return quantity;
    }

    /**
     * @return the loadQuantity
     */
    public Long getLoadQuantity() {
        return loadQuantity;
    }

    /**
     * @return the status
     */
    public Long getStatus() {
        return status;
    }

    /**
     * @return the shipmentDate
     */
    public Date getShipmentDate() {
        return shipmentDate;
    }

    /**
     * @return the loadingTime
     */
    public Date getLoadingTime() {
        return loadingTime;
    }

    /**
     * @return the leavingTime
     */
    public Date getLeavingTime() {
        return leavingTime;
    }

    /**
     * @return the arrivingTime
     */
    public Date getArrivingTime() {
        return arrivingTime;
    }

    /**
     * @return the accConfirmDate
     */
    public Date getAccConfirmDate() {
        return accConfirmDate;
    }

    /**
     * @return the accidentTime
     */
    public Date getAccidentTime() {
        return accidentTime;
    }

    /**
     * @return the operator
     */
    public String getOperator() {
        return operator;
    }

    /**
     * @return the lastModifiedDate
     */
    public Date getLastModifiedDate() {
        return lastModifiedDate;
    }

    /**
     * @return the accomplishConfirm
     */
    public Boolean getAccomplishConfirm() {
        return accomplishConfirm;
    }
    
    /**
     * @return
     */
    public Boolean getElectronicConfirm() {
        return electronicConfirm;
    }

    /**
     * @return the accident
     */
    public Boolean getAccident() {
        return accident;
    }

    /**
     * @return the disabled
     */
    public Boolean getDisabled() {
        return disabled;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param loadNumber the loadNumber to set
     */
    public void setLoadNumber(String loadNumber) {
        this.loadNumber = loadNumber;
    }

    /**
     * @param loadGroupNumber the loadGroupNumber to set
     */
    public void setLoadGroupNumber(String loadGroupNumber) {
        this.loadGroupNumber = loadGroupNumber;
    }

    /**
     * @param dispatchOrderId the dispatchOrderId to set
     */
    public void setDispatchOrderId(Long dispatchOrderId) {
        this.dispatchOrderId = dispatchOrderId;
    }

    /**
     * @param shipmentId the shipmentId to set
     */
    public void setShipmentId(Long shipmentId) {
        this.shipmentId = shipmentId;
    }

    /**
     * @param orderId the orderId to set
     */
    public void setOrderId(Long orderId) {
        this.orderId = orderId;
    }

    /**
     * @param loadId the loadId to set
     */
    public void setLoadId(Long loadId) {
        this.loadId = loadId;
    }

    /**
     * @param originalPlaceId the originalPlaceId to set
     */
    public void setOriginalPlaceId(Long originalPlaceId) {
        this.originalPlaceId = originalPlaceId;
    }

    /**
     * @param firstShipmentId the firstShipmentId to set
     */
    public void setFirstShipmentId(Long firstShipmentId) {
        this.firstShipmentId = firstShipmentId;
    }

    /**
     * @param balanceId the balanceId to set
     */
    public void setBalanceId(Long balanceId) {
        this.balanceId = balanceId;
    }

    /**
     * @param customerId the customerId to set
     */
    public void setCustomerId(Long customerId) {
        this.customerId = customerId;
    }

    /**
     * @param transCorpId the transCorpId to set
     */
    public void setTransCorpId(Long transCorpId) {
        this.transCorpId = transCorpId;
    }

    /**
     * @param vhModelId the vhModelId to set
     */
    public void setVhModelId(Long vhModelId) {
        this.vhModelId = vhModelId;
    }

    /**
     * @param transMeansId the transMeansId to set
     */
    public void setTransMeansId(Long transMeansId) {
        this.transMeansId = transMeansId;
    }

    /**
     * @param vhColorId the vhColorId to set
     */
    public void setVhColorId(Long vhColorId) {
        this.vhColorId = vhColorId;
    }

    /**
     * @param vhCartypeId the vhCartypeId to set
     */
    public void setVhCartypeId(Long vhCartypeId) {
        this.vhCartypeId = vhCartypeId;
    }

    /**
     * @param carSummary the carSummary to set
     */
    public void setCarSummary(String carSummary) {
        this.carSummary = carSummary;
    }

    /**
     * @param vinCode the vinCode to set
     */
    public void setVinCode(String vinCode) {
        this.vinCode = vinCode;
    }

    /**
     * @param driveWay the driveWay to set
     */
    public void setDriveWay(String driveWay) {
        this.driveWay = driveWay;
    }

    /**
     * @param shipSequence the shipSequence to set
     */
    public void setShipSequence(String shipSequence) {
        this.shipSequence = shipSequence;
    }

    /**
     * @param srcWhId the srcWhId to set
     */
    public void setSrcWhId(Long srcWhId) {
        this.srcWhId = srcWhId;
    }

    /**
     * @param destWhId the destWhId to set
     */
    public void setDestWhId(Long destWhId) {
        this.destWhId = destWhId;
    }

    /**
     * @param destContactPerson the destContactPerson to set
     */
    public void setDestContactPerson(String destContactPerson) {
        this.destContactPerson = destContactPerson;
    }

    /**
     * @param destContactPhone the destContactPhone to set
     */
    public void setDestContactPhone(String destContactPhone) {
        this.destContactPhone = destContactPhone;
    }

    /**
     * @param destContactAddr the destContactAddr to set
     */
    public void setDestContactAddr(String destContactAddr) {
        this.destContactAddr = destContactAddr;
    }

    /**
     * @param transType
     */
    public void setTransType(String transType) {
		this.transType = transType;
	}

    /**
     * @param quantity the quantity to set
     */
    public void setQuantity(Long quantity) {
        this.quantity = quantity;
    }

    /**
     * @param loadQuantity the loadQuantity to set
     */
    public void setLoadQuantity(Long loadQuantity) {
        this.loadQuantity = loadQuantity;
    }

    /**
     * @param status the status to set
     */
    public void setStatus(Long status) {
        this.status = status;
    }

    /**
     * @param shipmentDate the shipmentDate to set
     */
    public void setShipmentDate(Date shipmentDate) {
        this.shipmentDate = shipmentDate;
    }

    /**
     * @param loadingTime the loadingTime to set
     */
    public void setLoadingTime(Date loadingTime) {
        this.loadingTime = loadingTime;
    }

    /**
     * @param leavingTime the leavingTime to set
     */
    public void setLeavingTime(Date leavingTime) {
        this.leavingTime = leavingTime;
    }

    /**
     * @param arrivingTime the arrivingTime to set
     */
    public void setArrivingTime(Date arrivingTime) {
        this.arrivingTime = arrivingTime;
    }

    /**
     * @param accConfirmDate the accConfirmDate to set
     */
    public void setAccConfirmDate(Date accConfirmDate) {
        this.accConfirmDate = accConfirmDate;
    }

    /**
     * @param accidentTime the accidentTime to set
     */
    public void setAccidentTime(Date accidentTime) {
        this.accidentTime = accidentTime;
    }

    /**
     * @param operator the operator to set
     */
    public void setOperator(String operator) {
        this.operator = operator;
    }

    /**
     * @param lastModifiedDate the lastModifiedDate to set
     */
    public void setLastModifiedDate(Date lastModifiedDate) {
        this.lastModifiedDate = lastModifiedDate;
    }

    /**
     * @param accomplishConfirm the accomplishConfirm to set
     */
    public void setAccomplishConfirm(Boolean accomplishConfirm) {
        this.accomplishConfirm = accomplishConfirm;
    }
    
    /**
     * @param electronicConfirm
     */
    public void setElectronicConfirm(Boolean electronicConfirm) {
        this.electronicConfirm = electronicConfirm;
    }

    /**
     * @param accident the accident to set
     */
    public void setAccident(Boolean accident) {
        this.accident = accident;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(Boolean disabled) {
        this.disabled = disabled;
    }
    
    
    
    
    
    
    
    
}
